package com.youtui.common.util;

import java.util.Date;
import java.util.Random;

public class NextIdUtil {
    /**
     *  
     * @return
     */
    public static Long getNextId() {
        long our_epoch = 1314220021721L;
        int shard_id = 5;
        Date date = new Date();
        long time = date.getTime();
        int number = new Random().nextInt(100000) + 1;
        time = (time - our_epoch) << 23 | shard_id << 10 | number;
        return time;

    }
    
    /**
     *  
     * @param length 
     * @return
     */
    public static String getRandomString(int length) { 
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";     
        Random random = new Random();     
        StringBuffer sb = new StringBuffer();     
        for (int i = 0; i < length; i++) {     
            int number = random.nextInt(base.length());     
            sb.append(base.charAt(number));     
        }     
        return sb.toString();     
     } 
    /**
     *  
     * @param length 
     * @return
     */
    public static String getRandomNumString(int length) { 
        String base = "0123456789";     
        Random random = new Random();     
        StringBuffer sb = new StringBuffer();     
        for (int i = 0; i < length; i++) {     
            int number = random.nextInt(base.length());     
            sb.append(base.charAt(number));     
        }     
        return sb.toString();     
     } 
    
    
    public static void main(String[] args) {
    	System.out.println(NextIdUtil.getRandomNumString(4));
	}
}
